package banco;

import java.util.List;

import modelo.AtributoTipoRequisito;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class BancoAtributoTipoRequisito {
	
	public void salvar(AtributoTipoRequisito u) {
		Session sessao = null;
		Transaction tx = null;
		try {
			sessao = HibernateUtil.getSession();
			tx = sessao.beginTransaction();
			sessao.save(u);
			tx.commit();
		} catch (Exception ex) {
			tx.rollback();
			ex.printStackTrace();
		} finally {
			if (sessao != null) {
				try {
					sessao.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	public List<AtributoTipoRequisito> recuperar() {
		Session sessao = null;
		Transaction tx = null;
		List<AtributoTipoRequisito> atr = null;
		try {
			sessao = HibernateUtil.getSession();
			tx = sessao.beginTransaction();
			org.hibernate.Query q = sessao.createQuery("from AtributoTipoRequisito");
			atr = q.list();
		} catch (Exception ex) {
			tx.rollback();
			ex.printStackTrace();
		} finally {
			if (sessao != null) {
				try {
					sessao.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return atr;
	}
	
	public AtributoTipoRequisito recuperarPorNome(String satr) {
		Session sessao = null;
		Transaction tx = null;
		AtributoTipoRequisito atr = null;
		try {
			sessao = HibernateUtil.getSession();
			tx = sessao.beginTransaction();
			org.hibernate.Query q = sessao.createQuery("from AtributoTipoRequisito where nome = '" + satr + "'");
			atr = (AtributoTipoRequisito)q.uniqueResult();
		} catch (Exception ex) {
			tx.rollback();
			ex.printStackTrace();
		} finally {
			if (sessao != null) {
				try {
					sessao.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return atr;
	}
}
